<div class="row">
    <label>SEO Title</label>
    <?php echo CHtml::activeTextField($model,'seo_title'); ?>
</div>

<?php
// find 2 widgets metadata & facebook metadata
$seoWidgets = CmsWidget::model()->findAll("path IN ('Cms/widgets/metadata','Cms/widgets/facebookTag')");
$seoWidgetIds = array();
$widgetPaths = array();
foreach($seoWidgets as $widget)
{
    $seoWidgetIds[] = $widget->id;
    $widgetPaths[$widget->id] = $widget->path;
}
// find all 2 these widgets in this page revision
$criteria = new CDbCriteria();
$criteria->with = array('widget');
$criteria->addInCondition('widget.path',array('Cms/widgets/metadata','Cms/widgets/facebookTag'));
$criteria->compare('t.page_id',$model->page_id);
$criteria->compare('t.revision_id',$model->id);
$criteria->compare('t.status',true);
$pageWidgets = PageWidget::model()->findAll($criteria);
if (count($pageWidgets) > 0) :
    echo '<div class="rows seo-widgets"><label>SEO widgets :</label>';
    foreach($pageWidgets as $pageWidget) :
        $name = $pageWidget->widget->name.' - '.$pageWidget->id.' ('.$pageWidget->container.')';
        //find url update
        $params = array();
        if (is_string($pageWidget->widget_settings))
            $params = $this->evaluateExpression($pageWidget->widget_settings);
        if (is_array($params))
        {
            if (isset($params['widget']))
                $params = $params['widget'];
        }
        else
            $params = array();
        $params['page_widget_id'] = $pageWidget->id;
        $params['layout'] = 'popup';
        array_unshift($params, '/'.trim($pageWidget->widget->path,'/').'/update');
        $name = CHtml::link($name,$params, array('class'=>'widget-title','target'=>'_blank'));
?>
        <div><?php echo $name; ?></div>    
    <?php
    endforeach;
    echo '</div>';
    ?>
<script type="text/javascript">
$('.seo-widgets a').click(function(){
    var url = $(this).attr('href');
    $.fancybox({
        type: 'iframe',
        href: url,
        width: '100%',
        height: '100%',
        showCloseButton: true,
        hideOnOverlayClick: false,
        autoScale: false,
        titleShow: false
    });
    return false;    
});
</script>
<?php endif; ?>